$(function () {
  let id = location.href.substring(location.href.indexOf('=') + 1)
  getDetails()
  async function getDetails() {
    const { data: { data: res } } = await axios.get('http://124.223.14.236:3001/api/recipe/' + id)
    console.log(res);

    document.querySelector('.left img').src = 'http://124.223.14.236:3001/public/' + res.img
    $('.right h3').html(res.name)
    $('.right p').html(res.description)

  }

  getList()
  async function getList() {
    const { data: { data } } = await axios.get('http://124.223.14.236:3001/api/recipeInfo', {
      params: {
        recipe_id: id,
      }
    })
    console.log(data);
    if (data.length > 0) {
      const listStr = data.map(item => `
        <li>
          <a href="detail.html?id=${item.id}">
            <img src="http://124.223.14.236:3001/public/${item.img}" alt="" />
            <h3>${item.title}</h3>
          </a>
        </li>
      `).join('')
      $('.list-box').html(listStr)
    } else {
      document.body.innerHTML += '<p class="noinfo">没有美食了...</p>'
    }



  }
})